"""
2025/4/2  [力扣题目链接](https://leetcode.cn/problems/binary-search/)
"""
from typing import List
class Solution:
    def search(self, nums: List[int], target: int) -> int:
        left, right = 0, len(nums) - 1
        while left <= right:
            middle = left + (right - left) // 2
            if target < nums[middle]:
                right = middle -1
            elif target > nums[middle]:
                left = middle + 1
            else:
                return middle
        return -1
